clear
rng default

workers=600;
n_types=4;
all_years=1940:1:1967;
n_years=size(all_years,2);

fp0='.../SpecB'; %specify correct path

%MEN
for j=1:n_types

fp=['.../SpecB/M/M_', int2str(j)];  %specify correct path

for h=1:n_years

IdSetM_temp=cell(workers,1);
for ii = 1:workers
    filepath = fullfile( fp, ['IdSetM.' num2str(ii) '.mat'] );
    if exist( filepath, 'file' )
       A = getfield( load( filepath ), 'IdSetM' ); 
       IdSetM_temp{ii}=A{h};
    end
end
IdSetM_final= vertcat(IdSetM_temp{:}); 

outpath = fullfile( fp0, ['IdSetM'  num2str(all_years(h)) '_final_' num2str(j) '.mat'] );
save( outpath, 'IdSetM_final' );
end
end



%WOMEN
for j=1:n_types

fp=['.../SpecB/W/W_', int2str(j)];  %specify correct path

for h=1:n_years

IdSetW_temp=cell(workers,1);
for ii = 1:workers
    filepath = fullfile( fp, ['IdSetW.' num2str(ii) '.mat'] );
    if exist( filepath, 'file' )
       A = getfield( load( filepath ), 'IdSetW' ); 
       IdSetW_temp{ii}=A{h};
    end
end
IdSetW_final= vertcat(IdSetW_temp{:}); 

outpath = fullfile( fp0, ['IdSetW'  num2str(all_years(h)) '_final_' num2str(j) '.mat'] );
save( outpath, 'IdSetW_final' );
end
end

 

